package com.erb.controller.llb;

import com.erb.entity.*;
import com.erb.service.llb.IOtherService;
import com.erb.service.llb.IndexService;
import com.erb.service.llb.InvestService;
import com.erb.service.zwj.IAdminUserService;
import com.erb.service.zwj.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 首页控制器
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/base")
public class IndexController {
	@Autowired
	IndexService indexService;
	@Autowired
	ITypeService typeService;
	@Autowired
	IAdminUserService adminUserService;
	@Autowired
	InvestService investService;
	@Autowired
	IOtherService otherService;

	/**
	 * 获取轮播图
	 */
	@GetMapping("/findAdvertisement")
	public RespBean findAdvertisement() {
		List<Advertisement> advertisements = indexService.findAdvertisement(true);
		return RespBean.ok("查询成功", advertisements);
	}

	/**
	 * 获取公告
	 */
	@GetMapping("/findNotice")
	public RespBean findNotice() {
		List<Notice> notices = indexService.findNotice();
		return RespBean.ok("查询成功", notices);
	}

	/**
	 * 分页获取公告
	 *
	 * @param pager
	 * @return
	 */
	@GetMapping("/findNoticeWithPage")
	public Pager findNoticeWithPage(Pager pager) {
		pager.page(indexService.countNotice());
		List<Notice> notices = indexService.findNoticeWithPage(pager);
		pager.data = notices;
		return pager;
	}

	/**
	 * 获取公告
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/findNoticeById/{id}")
	public RespBean findNoticeById(@PathVariable int id) {
		Notice notice = indexService.findNoticeById(id);
		return RespBean.ok("查询成功", notice);
	}

	/**
	 * 获取项目分类
	 *
	 * @return
	 */
	@GetMapping("/findProType")
	public RespBean findProType() {
		List<Type> types = typeService.findAll(null);
		return RespBean.ok("查询成功", types);
	}

	/**
	 * 获取投资总金额
	 *
	 * @return
	 */
	@GetMapping("/countInvestMoney")
	public RespBean countInvestMoney() {
		Double count = investService.countInvestMoney();
		return RespBean.ok("查询成功", count);
	}

	/**
	 * 获取总收益金额
	 *
	 * @return
	 */
	@GetMapping("/sumProfit")
	public RespBean sumProfit() {
		Double count = otherService.sumProfit();
		return RespBean.ok("查询成功", count);
	}

	/**
	 * 获取投资次数
	 *
	 * @return
	 */
	@GetMapping("/sumInvest")
	public RespBean sumInvest() {
		int count = investService.sumInvest();
		return RespBean.ok("查询成功", count);
	}

	/**
	 * 获取所有注册用户
	 *
	 * @return
	 */
	@GetMapping("/countUser")
	public RespBean countUser() {
		int count = adminUserService.findCount();
		return RespBean.ok("查询成功", count);
	}

	/**
	 * 获取前五收益投资
	 *
	 * @return
	 */
	@GetMapping("/topFiveInvestAndProfit")
	public RespBean topFiveInvest() {
		List<UserCount> invests = otherService.topFiveInvest();
		List<UserCount> profits = otherService.topFiveProfit();
		Map map = new HashMap(2);
		map.put("invests", invests);
		map.put("profits", profits);
		return RespBean.ok("查询成功", map);
	}

}
